<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cole System Manage</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
</head>

<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">访客姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value=""
                    class="layui-input">

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">电话</label>
            <div class="layui-input-block">
                <input type="text" name="tel" lay-verify="required" lay-reqtext="电话不能为空" placeholder="请输入电话" value=""
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">地址</label>
            <div class="layui-input-block">
                <input type="text" name="address" lay-verify="required" lay-reqtext="地址不能为空" placeholder="请输入地址"
                    value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">风险地区</label>
            <div class="layui-input-block">
                <input type="radio" name="isrisk" value="低风险地区" title="低风险地区" checked="">
                <input type="radio" name="isrisk" value="中风险地区" title="中风险地区">
                <input type="radio" name="isrisk" value="高风险地区" title="高风险地区">

            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">来访时间</label>
            <div class="layui-input-block">
                <input type="text" name="entertime" id="enter" lay-verify="date" placeholder="yyyy-MM-dd"
                    autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">离开时间</label>
            <div class="layui-input-block">
                <input type="text" name="outtime" id="out" lay-verify="date" placeholder="yyyy-MM-dd"
                    autocomplete="off" class="layui-input">
            </div>
        </div>

        

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>

    <script>
        layui.use(['form', 'upload', 'element'], function () {
            var form = layui.form,
                layer = layui.layer,
                upload = layui.upload,
                element = layui.element,
                laydate = layui.laydate,//添加日期
                $ = layui.$;

            // 渲染日期组件
            laydate.render({
                elem: '#enter'
                
            });
            laydate.render({
                elem: '#out'
                
            });
            
            


            //监听提交
            form.on('submit(saveBtn)', function (data) {
                data = data.field;
                // var index = layer.alert(JSON.stringify(data), {
                //     title: '最终的提交信息'

                // }, function () {
                    
                // });
                $.ajax({
                        url: "http://localhost:8080/register/addRegister",
                        type: "post",
                        data: JSON.stringify(data),
                        contentType: "application/json",
                        success: function (result) {
                            if (result.code == 0) {

                                // 关闭弹出层
                                // layer.close(index);
                                parent.layer.msg("添加成功");
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                parent.reload;
                            } else {

                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.msg("添加失败");
                                parent.layer.close(iframeIndex);
                            }
                        },
                        dataType: "json"
                    })
                return false;
            });

        });
    </script>
</body>

</html>